package com.shopping.common.core.object;

import com.shopping.common.core.util.ContextUtil;
import lombok.Data;
import lombok.ToString;

import javax.naming.Context;
import javax.servlet.http.HttpServletRequest;

@Data
@ToString
public class TokenData {

    /**
     * 在HTTP Request对象中的属性键。
     */
    public static final String  REQUEST_ATTRIBUTE_NAME = "tokenData";
    /**
     * 用户id
     */
    private Long userId;
    /**
     * 用户名称
     */
    private String userName;

    public static void addRequest(TokenData tokenData){
        HttpServletRequest httpRequest = ContextUtil.getHttpRequest();
        httpRequest.setAttribute(TokenData.REQUEST_ATTRIBUTE_NAME,tokenData);
    }

    public static TokenData takeFormRequest(){
        HttpServletRequest httpRequest = ContextUtil.getHttpRequest();
        return (TokenData) httpRequest.getAttribute(REQUEST_ATTRIBUTE_NAME);
    }
}
